/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.pucp.TrabajoGrupal.Classes;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author andre
 */
public class ProjectModel extends AbstractTableModel{

    String [] colNames = new String[]{"ID", "Proyecto", "Inicio" , "Fin" };
    ArrayList<Project> data;
    public ProjectModel(){
        data = ( new ProjectDao() ).getProjects(); 
    }
    
    public void reload(){
        data = ( new ProjectDao() ).getProjects();
    }
    
    public String getColumnName( int col ){ return colNames[ col ]; }
    
    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return colNames.length;
    }

    @Override
    public Object getValueAt(int row, int col) {
        Project proj =  data.get( row );
        switch( col ){
            case 0 :    return proj.getId();
            case 1 :    return proj.getName();
            case 2 :    return proj.getStartDate();
            case 3 :    return proj.getFinishDate();
            default:    return null;   
        }
    }
    
}
